<?

  if (isset ($_POST['add_user']) AND $_POST['add_user'] != NULL)
   {
    mysql_connect ("localhost", "hof", "juillet");
    mysql_select_db ("hof");

    $nickname = mysql_real_escape_string(htmlspecialchars($_POST['add_user']));

    mysql_query ("INSERT INTO user_info VALUES(NULL, '$nickname', 0, 0)");
 
    mysql_close ();

    header ("Location:/hof");

    exit ();
    
  }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">

  <head>
    <title>Hall of Fame</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" type="text/css" href="css/style.css" media="screen,projection" />
  </head>

<body>

<div id="container"> 

<table id="hof_tab" summary="Hall of Fame leaderboard">

<thead>
<tr>
  <th scope="col" class="u_name">Users</th>
  <th scope="col" class="u_point">Points</th>
  <th scope="col" class="u_star">Stars</th>
  <th scope="col" class="u_action">-/+</th>
</tr>
</thead>

<tfoot>
<tr>

  <td colspan="3" class="foot_tab">
    <em>Not in the list ? Enter your name here</em>
    <form  id="user_act" method="post" action="">
    <div>
    <input type="text" name="add_user" value="" size="15" />
    <input type="submit" name="u_add" value="Add" />
    </div>
    </form>
  </td>
  <td class="right_foot_tab">
    <a href="/" title="refresh"><img src="img/refresh.png" alt="refresh" height="22" width="22"/></a>
  </td>
</tr>
</tfoot>

<tbody>

<?

  mysql_connect ("localhost", "hof", "juillet");
  mysql_select_db ("hof");

  $rep = mysql_query ("SELECT * FROM user_info ORDER BY u_stars DESC, u_points DESC") or die(mysql_error());

  $tbody_content = "";

  for ($i = 0; $tab_array = mysql_fetch_array ($rep); $i++)
   {   
    $user_name = $tab_array['u_name'];
    $user_points = $tab_array['u_points'];
    $user_stars = $tab_array['u_stars'];
    $user_id = $tab_array['u_id'];
    
    $tbody_content .=  "<tr>\n"
    . "  <td>$user_name</td>\n"
    . "  <td>$user_points</td>\n"
    . "  <td>";

    for ($y = 0; $y < $user_stars; $y++)
      $tbody_content .= "<img src=\"img/u_star.png\" alt=\"*\" title=\"A Star !\" height=\"16\" width=\"16\" />&nbsp;";

    $tbody_content .= "</td>\n"
    . "  <td>\n"
    . "    <a href=\"action.php?u_id=" . $user_id . "&amp;add_points=-1\" title=\"Bad\"><img src=\"img/bad.png\" height=\"24\" width=\"24\" alt=\"Loose a point\" /></a>\n"
    . "    <a href=\"action.php?u_id=" . $user_id . "&amp;add_points=1\" title=\"Good\"><img src=\"img/good.png\" height=\"24\" width=\"24\" alt=\"Win a point\" /></a>\n"
    . "  </td>\n"
    . "</tr>\n";
   }
   
  if ($i == 0)
   {
    $tbody_content = "<tr>\n"
    . "  <td></td>\n"
    . "  <td></td>\n"
    . "  <td></td>\n"
    . "  <td></td>\n"
    . "</tr>\n";
   }

  mysql_close ();

  echo $tbody_content;

?>

</tbody>

</table>

</div>

<hr />

<div id="foot_page">
  <p> 
		 <a href="http://validator.w3.org/check/referer" title="xhtml validator"><img src="img/xhtml.png" height="15" width="80" alt="xhtml validator" /></a>
		 <a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="img/firefox.png" width="80" height="15" alt="Get Firefox" /></a>
		 <a href="http://www.php.net/" title="Powered by PHP"><img src="img/php.png" width="80" height="15" alt="Powered by PHP" /></a>
  </p>
</div>

</body>

</html>

